<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>网络监听接口</title>
</head>
<body>
    <script>
        // online 当网络连通的时候触发
        // window.ononline
        window.addEventListener("online", function() {
            console.log("网络连通了")
        })
        
        // onoffline 当网络断开时触发
        // window.onoffline
        window.addEventListener("offline", function() {
            console.log("网络断开连接了")
        })
    </script>
</body>
</html>